package cn.gzmli.dtt.common.utils;

import java.util.Comparator;
import java.util.Map;

/**
 * Created by songcai.jiang  on 2018/4/3.
 */
public class ComMapObjCompatator implements Comparator<Map<String, Object>> {

    String mKey = "id";
    public ComMapObjCompatator(String key) {
        mKey = key;
    }

    @Override
    public int compare(Map<String, Object> o1, Map<String, Object> o2) {
        Integer id1 = (Integer) o1.get(mKey);
        Integer id2 = (Integer) o2.get(mKey);
        if (id1!=null&&id2!=null){
            if(id2 > id1){
                return -1;
            }else {
                return 1;
            }
        }
        if (id1!=null&& id2==null){
            return -1;
        }
        if (id1==null&& id2!=null){
            return 1;
        }
        return 0;
    }
}
